<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%--
  Created by IntelliJ IDEA.
  User: 15646
  Date: 2024/6/17
  Time: 15:23
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>

<html>
<head>
    <meta charset="UTF-8">
    <title>房间列表</title>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.3/css/all.min.css">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.5.2/css/bootstrap.min.css">
    <style>
        body {
            font-family: Arial, sans-serif;
        }
        .sidebar {
            width: 250px;
            position: fixed;
            top: 0;
            left: 0;
            height: 100%;
            background-color: #343a40;
            color: white;
            padding-top: 20px;
        }
        .sidebar a {
            padding: 10px 15px;
            text-decoration: none;
            font-size: 18px;
            color: white;
            display: block;
        }
        .sidebar a:hover {
            background-color: #575d63;
        }
        .content {
            margin-left: 250px;
            padding: 20px;
        }
        .header {
            background-color: #f8f9fa;
            padding: 10px;
            display: flex;
            justify-content: space-between;
            align-items: center;
            box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
        }
        .header h1 {
            margin: 0;
        }
        .header .user-info {
            display: flex;
            align-items: center;
        }
        .header .user-info span {
            margin-right: 10px;
        }
        .table-container {
            margin-top: 20px;
        }
    </style>
</head>
<body>

<div class="sidebar">
    <h2 class="text-center">酒店后端管理</h2>
    <a href="${pageContext.request.contextPath}/FindCustomerByPageServlet">顾客管理</a>
    <a href="#">房间管理</a>
    <a href="${pageContext.request.contextPath}/FindOrderByPageServlet">订单管理</a>


</div>

<div class="content">
    <div class="header">
        <h1>房间列表</h1>
        <div class="user-info">
            <span>admin</span>
            <a  class="btn btn-outline-secondary btn-sm"
                href="${pageContext.request.contextPath}/login.jsp">
                前台首页
            </a>
        </div>
    </div>

    <div class="table-container">
        <div class="mb-3">
            <button class="btn btn-danger" form="roomlist" >批量删除</button>
            <button class="btn btn-success" data-toggle="modal" data-target="#addOrderModal">添加</button>
            <a href="${pageContext.request.contextPath}/tuichuServlet"
               class="btn btn-outline-secondary btn-sm"
               style="float: right">
                退出
            </a>
        </div>
        <form id="roomlist" action="${pageContext.request.contextPath}/DeleteRoomServlet" method="post">
            <table class="table table-bordered table-striped">
                <thead>
                <tr>
                    <th><input type="checkbox" id="selectAll"></th>
                    <th>房间名</th>
                    <th>价钱</th>
                    <th>面积</th>
                    <th>剩余房间</th>
                    <th>操作</th>
                </tr>
                </thead>
                <tbody>
                <c:forEach var="room" items="${pb.list}">
                    <tr>
                        <td><input type="checkbox" name="ruid" value="${room.room_id}"> </td>
                        <td>${room.room_name}</td>
                        <td>${room.room_price}元/天</td>
                        <td>${room.room_area}平方米</td>
                        <td>${room.room_remains}</td>
                        <td><button class="btn btn-danger">
                            <a href="${pageContext.request.contextPath}/DeleteRoomServlet?ruid=${room.room_id}">
                                删除
                            </a>
                            </button>
                            <button type="button" class="btn btn-success"
                                    data-toggle="modal" data-target="#alterRoom"
                                    onclick="updateRoomrId(${room.room_id})">
                                修改
                            </button>
                        </td>
                        </td>
                    </tr>
                </c:forEach>
                </tbody>
            </table>
        </form>

        <nav aria-label="Page navigation">
            <ul class="pagination justify-content-center">
                <c:if test="${pb.currentPage!=1}">
                    <li class="page-item">
                        <a class="page-link" href="${pageContext.request.contextPath}/FindRoomByPageServlet?currentPage=${pb.currentPage-1}&rows=5">
                            <<
                        </a>
                    </li>
                </c:if>

                <c:forEach begin="1" end="${pb.totalPage}" var="i">
                    <li class="page-item">
                        <a class="page-link"
                           href="${pageContext.request.contextPath}/FindRoomByPageServlet?currentPage=${i}&rows=5">
                                ${i}
                        </a>
                    </li>
                </c:forEach>
                <c:if test="${pb.currentPage != pb.totalPage}">
                    <li class="page-item">
                        <a class="page-link" href="${pageContext.request.contextPath}/FindRoomByPageServlet?currentPage=${pb.currentPage+1}&rows=5">
                            >>
                        </a>
                    </li>
                </c:if>
            </ul>
        </nav>
    </div>
</div>

<!-- 添加房间模态框 -->
<div class="modal fade" id="addOrderModal" tabindex="-1" aria-labelledby="addOrderModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title" id="addOrderModalLabel">添加房间</h5>
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
            </div>
            <div class="modal-body">
                <form  id="addOrderForm" method="post"
                       action="${pageContext.request.contextPath}/AddRoomServlet" >
                    <div class="form-group">
                        <label for="room_name">房间名</label>
                        <input type="text" class="form-control" id="room_name" name="room_name" required>
                    </div>
                    <div class="form-group">
                        <label for="room_price">价钱</label>
                        <input type="text" class="form-control" id="room_price" name="room_price" required>
                    </div>
                    <div class="form-group">
                        <label for="room_area">面积</label>
                        <input type="text" class="form-control" id="room_area" name="room_area" required>
                    </div>
                    <div class="form-group">
                        <label for="room_remains">剩余房间</label>
                        <input type="text" class="form-control" id="room_remains" name="room_remains" required>
                    </div>

                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-secondary" data-dismiss="modal">取消</button>
                <button type="submit" class="btn btn-primary" form="addOrderForm">提交</button>
            </div>
        </div>
    </div>
</div>
<!-- 修改房间模态框 -->
<div class="modal fade" id="alterRoom" tabindex="-1" aria-labelledby="addOrderModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title" id="alterRoomLabel">添加房间</h5>
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
            </div>
            <div class="modal-body">
                <form  id="alterRoomForm" method="post"
                       action="${pageContext.request.contextPath}/AlterRoomServlet" >
                    <div class="form-group">
                        <label for="room_name">房间ID</label>
                        <input type="text" class="form-control" id="alroom_id" name="room_id" readonly>
                    </div>
                    <div class="form-group">
                        <label for="room_name">房间名</label>
                        <input type="text" class="form-control" id="alroom_name" name="room_name" required>
                    </div>
                    <div class="form-group">
                        <label for="room_price">价钱</label>
                        <input type="text" class="form-control" id="alroom_price" name="room_price" required>
                    </div>
                    <div class="form-group">
                        <label for="room_area">面积</label>
                        <input type="text" class="form-control" id="alroom_area" name="room_area" required>
                    </div>
                    <div class="form-group">
                        <label for="room_remains">剩余房间</label>
                        <input type="text" class="form-control" id="alroom_remains" name="room_remains" required>
                    </div>

                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-secondary" data-dismiss="modal">取消</button>
                <button type="submit" class="btn btn-primary" form="alterRoomForm">提交</button>
            </div>
        </div>
    </div>
</div>

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.5.2/js/bootstrap.bundle.min.js"></script>
<script>
    i =1;
    function updateRoomrId(newID){
        i=newID;
        document.getElementById('alroom_id').value = i;
    }
    document.getElementById('selectAll').addEventListener('click', function() {
        var checkboxes = document.getElementsByName('ruid');
        for (var checkbox of checkboxes) {
            checkbox.checked = this.checked;
        }
    });
</script>

</body>
</html>
